# -*- coding:utf8 -*-
import datetime
import time

def get_current_time():
    """
    得到当前时间
    :return:
    """
    return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")


def get_all_filter_words(path):
    """
    得到所有的停词信息
    :param path: 停词表的路径
    :return:
    """
    with open(path, 'r') as fs:
        result = fs.read()
    if len(result) < 1:
        return None
    # 变成数组，容易遍历
    result = result.split('\n')
    return result


def change_datetime_2_timestap(dt):
    """
    将datetime转化成10位的时间戳函数
    :param dt: datetime
    :return: 10位的时间戳
    """
    return int(time.mktime(time.strptime(dt, "%Y-%m-%d %H:%M:%S")))


def change_str_2_datetime(s):
    """
    将字符串转datetime
    :param s: 时间字符串如:'2017-01-01 00:20:10'
    :return:
    """
    return datetime.datetime.strptime(s, "%Y-%m-%d %H:%M:%S")


def get_before_date_by_delta(current_date, delta_days):
    """
    根据当前时间得到delta_days天前的时间
    :param current_date: 当前时间,如:'2017-02-03 14:12:20'
    :return: result delta_days天前的时间 类型:str
    """
    if delta_days > 0:
        delta_days = -delta_days
    result = change_str_2_datetime(current_date) + datetime.timedelta(days=delta_days)
    result = datetime.datetime.strftime(result, "%Y-%m-%d %H:%M:%S")
    return result


def init_by_other_arr(arr, other_arr):
    nums = len(other_arr)
    for i in range(nums):
        arr.append(0)
    return arr


def find_index_in_arr(word, arr):
    """
    寻找word是否在arr中，在的话返回所在位置，否则-1
    :param word: 需要寻找的单词
    :param arr: 单词集合
    :return:
    """
    for i in range(len(arr)):
        if word in arr[i]:
            return i
    return -1

if __name__ == '__main__':
    datestr1 = '2015-06-06 10:10:10'
    datestr2 = '2015-06-07 10:10:10'
    print datestr1 > datestr2
    delta = 40
    print '1 day before is :', get_before_date_by_delta(datestr1, delta)
